package com.ruoyi.animal.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.animal.domain.AnimalInformation;
import com.ruoyi.animal.domain.AnimalSpecies;
import com.ruoyi.animal.service.IAnimalInformationService;
import com.ruoyi.animal.service.IAnimalSpeciesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.animal.domain.AnimalCare;
import com.ruoyi.animal.service.IAnimalCareService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 动物照料Controller
 * 
 * @author gw
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/care")
public class AnimalCareController extends BaseController
{
    @Autowired
    private IAnimalCareService animalCareService;

    @Autowired
    private IAnimalInformationService animalInformationService;

    /**
     * 查询动物照料列表
     */
    @RequiresPermissions("animal:care:list")
    @GetMapping("/list")
    public TableDataInfo list(AnimalCare animalCare)
    {
        startPage();
        List<AnimalCare> list = animalCareService.selectAnimalCareList(animalCare);
        for(AnimalCare animalCare1:list){
            AnimalInformation animalInformation = animalInformationService.selectAnimalInformationByAnimalId(animalCare1.getAnimalId());
            if(animalInformation!=null) {
                animalCare1.setAnimalNumber(animalInformation.getAnimalNumber());
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出动物照料列表
     */
    @RequiresPermissions("animal:care:export")
    @Log(title = "动物照料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AnimalCare animalCare)
    {
        List<AnimalCare> list = animalCareService.selectAnimalCareList(animalCare);
        ExcelUtil<AnimalCare> util = new ExcelUtil<AnimalCare>(AnimalCare.class);
        util.exportExcel(response, list, "动物照料数据");
    }

    /**
     * 获取动物照料详细信息
     */
    @RequiresPermissions("animal:care:query")
    @GetMapping(value = "/{careId}")
    public AjaxResult getInfo(@PathVariable("careId") Long careId)
    {
        return success(animalCareService.selectAnimalCareByCareId(careId));
    }

    /**
     * 新增动物照料
     */
    @RequiresPermissions("animal:care:add")
    @Log(title = "动物照料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AnimalCare animalCare)
    {
        return toAjax(animalCareService.insertAnimalCare(animalCare));
    }

    /**
     * 修改动物照料
     */
    @RequiresPermissions("animal:care:edit")
    @Log(title = "动物照料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AnimalCare animalCare)
    {
        return toAjax(animalCareService.updateAnimalCare(animalCare));
    }

    /**
     * 删除动物照料
     */
    @RequiresPermissions("animal:care:remove")
    @Log(title = "动物照料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{careIds}")
    public AjaxResult remove(@PathVariable Long[] careIds)
    {
        return toAjax(animalCareService.deleteAnimalCareByCareIds(careIds));
    }
}
